USE [master]
GO
/****** Object:  Database [OnlineTestSystem]    Script Date: 2020/5/11 13:17:20 ******/
CREATE DATABASE [OnlineTestSystem]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'OnlineTestSystem', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\OnlineTestSystem.mdf' , SIZE = 4160KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'OnlineTestSystem_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\OnlineTestSystem_log.ldf' , SIZE = 1040KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [OnlineTestSystem] SET COMPATIBILITY_LEVEL = 110
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [OnlineTestSystem].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [OnlineTestSystem] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET ARITHABORT OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [OnlineTestSystem] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [OnlineTestSystem] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [OnlineTestSystem] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET  ENABLE_BROKER 
GO
ALTER DATABASE [OnlineTestSystem] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [OnlineTestSystem] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET RECOVERY FULL 
GO
ALTER DATABASE [OnlineTestSystem] SET  MULTI_USER 
GO
ALTER DATABASE [OnlineTestSystem] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [OnlineTestSystem] SET DB_CHAINING OFF 
GO
ALTER DATABASE [OnlineTestSystem] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [OnlineTestSystem] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO
EXEC sys.sp_db_vardecimal_storage_format N'OnlineTestSystem', N'ON'
GO
USE [OnlineTestSystem]
GO
/****** Object:  Table [dbo].[Administrator]    Script Date: 2020/5/11 13:17:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Administrator](
	[Aid] [int] NOT NULL,
	[Apwd] [nvarchar](50) NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[Aid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Class]    Script Date: 2020/5/11 13:17:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Class](
	[ClassID] [int] NOT NULL,
	[ClassName] [nvarchar](30) NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[ClassID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Course]    Script Date: 2020/5/11 13:17:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Course](
	[CourseID] [int] NOT NULL,
	[CourseName] [nvarchar](30) NOT NULL,
	[Tid] [int] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[CourseID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Grades]    Script Date: 2020/5/11 13:17:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Grades](
	[Sid] [int] NOT NULL,
	[ClassName] [nvarchar](30) NOT NULL,
	[CourseName] [nvarchar](30) NOT NULL,
	[Grade] [int] NOT NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Student]    Script Date: 2020/5/11 13:17:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Student](
	[Sid] [int] NOT NULL,
	[Sname] [nvarchar](30) NOT NULL,
	[Spwd] [nvarchar](50) NOT NULL,
	[Sgender] [char](2) NOT NULL,
	[ClassID] [int] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[Sid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Teachers]    Script Date: 2020/5/11 13:17:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Teachers](
	[Tid] [int] NOT NULL,
	[Tname] [nvarchar](30) NOT NULL,
	[Tpwd] [nvarchar](50) NOT NULL,
	[Tstatus] [int] NULL,
	[CourseID] [int] NULL,
	[ClassID] [int] NULL,
PRIMARY KEY CLUSTERED 
(
	[Tid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Test]    Script Date: 2020/5/11 13:17:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Test](
	[TestID] [int] NOT NULL,
	[CourseID] [int] NOT NULL,
	[Tid] [int] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[TestID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TestQuestions]    Script Date: 2020/5/11 13:17:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TestQuestions](
	[Topic] [text] NOT NULL,
	[A] [text] NOT NULL,
	[B] [text] NOT NULL,
	[C] [text] NOT NULL,
	[D] [text] NOT NULL,
	[RightAnswer] [nvarchar](2) NOT NULL,
	[Score] [int] NOT NULL,
	[Subject] [text] NOT NULL,
	[Tqid] [int] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
ALTER TABLE [dbo].[Teachers] ADD  DEFAULT ((1)) FOR [Tstatus]
GO
ALTER TABLE [dbo].[TestQuestions] ADD  DEFAULT ((2)) FOR [Score]
GO
ALTER TABLE [dbo].[Course]  WITH CHECK ADD  CONSTRAINT [FK_ID] FOREIGN KEY([Tid])
REFERENCES [dbo].[Teachers] ([Tid])
GO
ALTER TABLE [dbo].[Course] CHECK CONSTRAINT [FK_ID]
GO
ALTER TABLE [dbo].[Grades]  WITH CHECK ADD FOREIGN KEY([Sid])
REFERENCES [dbo].[Student] ([Sid])
GO
ALTER TABLE [dbo].[Student]  WITH CHECK ADD  CONSTRAINT [FK_ID4] FOREIGN KEY([ClassID])
REFERENCES [dbo].[Class] ([ClassID])
GO
ALTER TABLE [dbo].[Student] CHECK CONSTRAINT [FK_ID4]
GO
ALTER TABLE [dbo].[Teachers]  WITH CHECK ADD  CONSTRAINT [FK_ID2] FOREIGN KEY([CourseID])
REFERENCES [dbo].[Course] ([CourseID])
GO
ALTER TABLE [dbo].[Teachers] CHECK CONSTRAINT [FK_ID2]
GO
ALTER TABLE [dbo].[Teachers]  WITH CHECK ADD  CONSTRAINT [FK_ID3] FOREIGN KEY([ClassID])
REFERENCES [dbo].[Class] ([ClassID])
GO
ALTER TABLE [dbo].[Teachers] CHECK CONSTRAINT [FK_ID3]
GO
ALTER TABLE [dbo].[Test]  WITH CHECK ADD  CONSTRAINT [FK_ID5] FOREIGN KEY([CourseID])
REFERENCES [dbo].[Course] ([CourseID])
GO
ALTER TABLE [dbo].[Test] CHECK CONSTRAINT [FK_ID5]
GO
ALTER TABLE [dbo].[Test]  WITH CHECK ADD  CONSTRAINT [FK_ID6] FOREIGN KEY([Tid])
REFERENCES [dbo].[Teachers] ([Tid])
GO
ALTER TABLE [dbo].[Test] CHECK CONSTRAINT [FK_ID6]
GO
ALTER TABLE [dbo].[Teachers]  WITH CHECK ADD CHECK  (([Tstatus]='1' OR [Tstatus]='0'))
GO
USE [master]
GO
ALTER DATABASE [OnlineTestSystem] SET  READ_WRITE 
GO
